package com.yz.administrator.jiukuaijiu.ui.shop;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.yz.administrator.jiukuaijiu.R;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/2/28.
 */

public class ShopAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {


    private ArrayList<ShopBean> data;
    private Context context;
    private LayoutInflater inflater;


    public ShopAdapter(Context context, ArrayList<ShopBean> data) {
        this.context = context;
        this.data = data;
        inflater = LayoutInflater.from(context);
    }


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = inflater.inflate(R.layout.shopitem_layout, parent, false);
        return new ShopHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof ShopHolder) {
            ShopHolder shopHolder = (ShopHolder) holder;

            ShopBean shopBean = data.get(position);


            shopHolder.shopBottomTitle.setText(shopBean.getTitle());
            shopHolder.shopBottomPrice.setText("¥ "+shopBean.getNew_price());
            String pic_url = shopBean.getPic_url();

            //   mTitle.setText(shopBean.getTitle());
            //  mPrice.setText(shopBean.getNew_price());
            // String imgeurl = shopBean.getPic_url();

            Glide.with(context).load(pic_url)
                    .placeholder(R.mipmap.ic_launcher)
                    .error(R.mipmap.ic_launcher)
                    .into(shopHolder.shopBottomImage);
        }
    }

    @Override
    public int getItemCount() {
        return data != null ? data.size() : 0;
    }

    class ShopHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.shop_bottom_image)
        ImageView shopBottomImage;
        @BindView(R.id.shop_bottom_title)
        TextView shopBottomTitle;
        @BindView(R.id.shop_bottom_price)
        TextView shopBottomPrice;
        public ShopHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }

}
